<?php
/*
 * @Author: SunnyJ
 * @Date: 2021-05-03 11:03:25
 * @LastEditors: SunnyJ
 * @LastEditTime: 2021-06-02 11:51:34
 */


namespace app\api\controller;
use think\Response;

// API基类，实现基本格式
abstract class Base2
{
	// 创建标准API
	protected function create($result, $desc = '', $success = true, $type = 'json')
	{
		if ($desc == '') {
			$result = [
				// 状态标识
				'success'	=> $success,
				// 结果
				'result'	=> $result
			];
		} elseif ($success == false and $result == '') {
			$result = [
				// 状态标识
				'success'	=> $success,
				// description
				'desc'		=> $desc,
			];
		} else {
			$result = [
				// 状态标识
				'success'	=> $success,
				// description
				'desc'		=> $desc,
				// 结果
				'result'	=> $result
			];
		}
		// 返回API
		return Response::create($result, $type);
	}

	public function __call($name, $arguments) {
		// 404 wrong url
		return $this -> create([],$desc = 'Wrong url', $success = false);
	}
}
?>
